package com.example.javatest.controller;

import com.example.javatest.common.CommonHeader;
import com.example.javatest.common.ResetApiUrls;
import com.example.javatest.common.RestResponse;
import jakarta.annotation.Resource;
import org.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@RestController
public class HotChangesController {
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/v1/getHostChangeList")
    public RestResponse getHostChanges() {
        HttpHeaders headers = new HttpHeaders();
        for (Map.Entry<String, String> headerItem : CommonHeader.httpHeader.entrySet()) {
            headers.set(headerItem.getKey(), headerItem.getValue());
        }
        HttpEntity<String> entity = new HttpEntity<>("", headers);
        ResponseEntity<String> result = restTemplate.exchange(ResetApiUrls.hotChangeUrl, HttpMethod.GET, entity, String.class);
        JSONObject jsonObject = new JSONObject(result.getBody());
        System.out.print(jsonObject);

        return new RestResponse(200,"test","success");
    }
}
